package day05;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/14
 */

/**
 * String
 * 1.引用数据类型
 * 2.字符串的数据类型
 * 3.默认值null
 * 4.不可变字符串  public final class String
 * 5.String的创建方式
 * 方式一：类似于基本数据类型，直接赋值   "字符串常量池"
 * String str = "abc";
 * 方式二：通过构造方法创建对象  "堆内存"
 * String str = new String("abc");
 */


import java.util.Arrays;

/**
 * String <----> 数组 之间的转换
 * 1.已知数组，转String类型
 * 1.1 public String(byte bytes[])
 * 1.2 public String(byte bytes[], String charsetName)
 * 1.3 public String(char value[])
 *
 * 构造方法
 * 1.1 public String(StringBuffer buffer)
 * 1.2 public String(StringBuilder builder)
 *
 * 2.已知String类型，转数组
 * 2.1 public byte[] getBytes()
 * 2.2 public byte[] getBytes(String charsetName)
 * 2.3 public char[] toCharArray()
 * 2.4 public String[] split(String regex)
 */


public class StringDemo {
    public static void main(String[] args) {
        String s1 = "abc";
        String s2 = new String("bbb");
        System.out.println("s1=" + s1 + ", s2=" + s2);


        byte[] arr1 = {97,98,99,100};
        System.out.println(new String(arr1));

        char[] arr2 = {'a','b','c'};
        System.out.println(new String(arr2));

        String s3 = "abc";
        System.out.println(Arrays.toString(s3.getBytes()));

        String s4 = "def";
        System.out.println(Arrays.toString(s4.toCharArray()));

        String s5 = "hello@world@you";
        System.out.println(Arrays.toString(s5.split("@")));
    }
}
